package com.qqim.common.entity;

import java.io.Serializable;
import java.util.Objects;

/**
 * 消息实体类
 */
public class Message implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /** 消息唯一标识 */
    private String messageId;
    
    /** 发送者ID */
    private String senderId;
    
    /** 接收者ID */
    private String receiverId;
    
    /** 消息内容 */
    private String content;
    
    /** 消息类型：text-文本, image-图片, file-文件 */
    private String messageType;
    
    /** 发送时间 */
    private long timestamp;
    
    /** 消息状态：sent-已发送, delivered-已送达, read-已读 */
    private String status;
    
    /** 文件路径（用于图片、文件消息） */
    private String filePath;
    
    /** 文件大小（字节） */
    private long fileSize;
    
    public Message() {}
    
    public Message(String senderId, String receiverId, String content, String messageType) {
        this.messageId = generateMessageId();
        this.senderId = senderId;
        this.receiverId = receiverId;
        this.content = content;
        this.messageType = messageType;
        this.timestamp = System.currentTimeMillis();
        this.status = "sent";
    }
    
    public static Message createTextMessage(String senderId, String receiverId, String content) {
        return new Message(senderId, receiverId, content, "text");
    }
    
    public static Message createImageMessage(String senderId, String receiverId, String filePath, long fileSize) {
        Message message = new Message(senderId, receiverId, "[图片]", "image");
        message.setFilePath(filePath);
        message.setFileSize(fileSize);
        return message;
    }
    
    private String generateMessageId() {
        return System.currentTimeMillis() + "_" + Math.random();
    }
    
    public String getMessageId() {
        return messageId;
    }
    
    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }
    
    public String getSenderId() {
        return senderId;
    }
    
    public void setSenderId(String senderId) {
        this.senderId = senderId;
    }
    
    public String getReceiverId() {
        return receiverId;
    }
    
    public void setReceiverId(String receiverId) {
        this.receiverId = receiverId;
    }
    
    public String getContent() {
        return content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    public String getMessageType() {
        return messageType;
    }
    
    public void setMessageType(String messageType) {
        this.messageType = messageType;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public String getFilePath() {
        return filePath;
    }
    
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
    
    public long getFileSize() {
        return fileSize;
    }
    
    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Message message = (Message) o;
        return Objects.equals(messageId, message.messageId);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(messageId);
    }
    
    @Override
    public String toString() {
        return "Message{" +
                "messageId='" + messageId + '\'' +
                ", senderId='" + senderId + '\'' +
                ", receiverId='" + receiverId + '\'' +
                ", content='" + content + '\'' +
                ", messageType='" + messageType + '\'' +
                ", timestamp=" + timestamp +
                ", status='" + status + '\'' +
                '}';
    }
} 